package com.haitaoit.chengquan.utils;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.widget.TextView;

import com.haitaoit.chengquan.R;

/**
 * 自定义加载进度条dialog
 * <p>
 * loadingDialog
 * <p>
 * 刘霄鹏
 * <p>
 * 2015年2月10日 上午11:35:18
 *
 * @version 1.0.0
 */

public class loadingDialog extends Dialog {
    private static Context context = null;
    private static loadingDialog customProgressDialog = null;

    private boolean iscancelable = true;

    public loadingDialog(Context context, int theme) {
        super(context, theme);
    }

    public static loadingDialog createDialog(Context context) {
        loadingDialog.context = context;
        customProgressDialog = new loadingDialog(context,
                R.style.CustomProgressDialog);
        customProgressDialog.setContentView(R.layout.customprogressdialog);
        customProgressDialog.getWindow().getAttributes().gravity = Gravity.CENTER;
        return customProgressDialog;
    }

    @Override
    public void show() {
        this.setCancelable(iscancelable);
        if (context != null) {
            super.show();
        }
    }

    public void set_Cancelable(boolean cancelable) {
        this.iscancelable = cancelable;
    }

    public void onWindowFocusChanged(boolean hasFocus) {
        if (customProgressDialog == null) {
            return;
        }

//		ImageView imageView = (ImageView) customProgressDialog
//				.findViewById(R.id.loadingImageView);
//		AnimationDrawable animationDrawable = (AnimationDrawable) imageView
//				.getBackground();
//		animationDrawable.start();
    }

    /**
     * [Summary] setTitile 标题
     *
     * @param strTitle
     * @return
     */
    public loadingDialog setTitile(String strTitle) {
        return customProgressDialog;
    }

    /**
     * [Summary] setMessage 提示内容
     *
     * @param strMessage
     * @return
     */
    public loadingDialog setMessage(String strMessage) {
        TextView tvMsg = (TextView) customProgressDialog
                .findViewById(R.id.id_tv_loadingmsg);
        if (tvMsg != null) {
            tvMsg.setText(strMessage);
        }
        return customProgressDialog;
    }
}
